﻿using System.ComponentModel;
using System.Data;
using System.Windows.Controls;
using System.Windows;
using De.TorstenMandelkow.MetroChart;
using System.Windows.Media;
namespace WPFExcelReport.Chart
{

    public partial class ChartExBase : UserControl
    {
        public bool IsLoaded = false;
        public ChartExViewModel vm; 
        public double RATIO
        {
            get
            {
                return vm.RATIO;
            }
            set
            {
                vm.RATIO = value;
            }
        }
        public double Converter
        {
            get
            {
                return vm.Converter;
            }
            set
            {
                vm.Converter = value;
                SetConverter();                
            }
        }
        public virtual void SetConverter()
        {
            if (vm.Converter == 0.001)
            {
                vm.ChartSubTitle = vm.DefaultSubTitle + "(千)";

            }
            if (vm.Converter == 0.0001)
            {
                vm.ChartSubTitle = vm.DefaultSubTitle + "(万)";
            }
            if (vm.Converter == 0.000001)
            {
                vm.ChartSubTitle = vm.DefaultSubTitle + "(百万)";
            }
        }
        public ChartExBase()
        {
            Loaded += ChartEx_Loaded;
        }

        public virtual void ChartEx_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            if (vm == null)
            {
                vm = DataContext as ChartExViewModel;
            }
            IsLoaded = true;
        }
        public virtual void SetChartSleep()
        {
            vm.IsSleep = true;

        }
      
        public virtual void SetChartGetUp()
        {
            vm.IsSleep = false;
            vm.IsRowColumnSwitched = true;
            vm.IsRowColumnSwitched = false;
        }
        public virtual void ResetChart()
        {
            vm.ResetChart();
        }

        public virtual void SetUp(int iData, string name, DataTable tb, string X, string Y)
        {
            vm.ChartTitle = vm.DefaultTitle;
            vm.ChartTitle1 = name;
            vm.ChartSubTitle1 = vm.ChartSubTitle;
            vm.ChartTitle2 = name;
            vm.ChartSubTitle2 = vm.ChartSubTitle;
            vm.ChartTitle3 = name;
            vm.ChartSubTitle3 = vm.ChartSubTitle;
            vm.ChartTitle4 = name;
            vm.ChartSubTitle4 = vm.ChartSubTitle;
            vm.ChartTitle5 = name;
            vm.ChartSubTitle5 = vm.ChartSubTitle;
            vm.SetUp(iData, name, tb, X, Y);
        }
        public virtual void Confirm()
        {
            vm.Confirm();
        }
    }
}
